<?php

namespace app\shop\job;

use sheep\job\BaseJob;
use think\queue\Job;
use app\shop\service\commission\Agent as AgentService;
use think\facade\Log;

/**
 * 分销任务
 */
class Commission extends BaseJob
{

    /**
     * 分销商升级
     */
    public function agentUpgrade(Job $job, $payload)
    {
        try {
            $userId = $payload['user_id'];
            $agent = new AgentService($userId);

            if ($agent->user) {
                \think\facade\Db::transaction(function () use ($agent) {
                    $agent->runAgentUpgradePlan();
                });
            }
            $job->delete();
        } catch (\Exception $e) {
            format_log_error($e, 'AgentUpgrade', '分销商升级队列');
        }
    }
}
